﻿Imports System.Data
Imports System.Data.SqlClient
Imports Bussines.entity

Public Class asuntoDAL
    Private conexion As New conexion
    Public Function buscarAsuntosPorEquipo(ByVal busqueda As String, ByVal idEquipo As String) As DataTable
        Dim dt As New DataTable
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "pdo_sp_ListaAsuntos"
        cmd.Parameters.Add(New SqlParameter("@equipo_id", SqlDbType.VarChar)).Value = idEquipo
        cmd.Parameters.Add(New SqlParameter("@busqueda", SqlDbType.VarChar)).Value = busqueda

        Try
            cmd.Connection = conexion.abrir()
            dt.Load(cmd.ExecuteReader())
            cmd.Dispose()
            conexion.Cerrar()
            Return dt
        Catch ex As Exception
            Return dt
        Finally

        End Try
    End Function

    Public Function GrabarAsunto(ByVal BEasunto As asuntoBE) As String
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "pdo_sp_InsertarAsunto"
        cmd.Parameters.Add(New SqlParameter("@idAsunto", SqlDbType.Int)).Value = BEasunto.idAsunto
        cmd.Parameters.Add(New SqlParameter("@descAsunto", SqlDbType.VarChar)).Value = BEasunto.descAsunto
        cmd.Parameters.Add(New SqlParameter("@equipo_id", SqlDbType.VarChar)).Value = BEasunto.equipo_id
        cmd.Parameters.Add(New SqlParameter("@activo", SqlDbType.Int)).Value = BEasunto.activo
        cmd.Parameters.Add(New SqlParameter("@idAsuntoReturn", SqlDbType.Int))
        cmd.Parameters("@idAsuntoReturn").Direction = ParameterDirection.Output

        Try
            cmd.Connection = conexion.abrir()
            cmd.ExecuteNonQuery()
            Dim intCod As Integer = Convert.ToInt32(cmd.Parameters("@idAsuntoReturn").Value.ToString())
            cmd.Dispose()
            conexion.Cerrar()
            Return intCod.ToString()
        Catch ex As Exception
            Return ex.Message
        Finally

        End Try
    End Function
End Class
